#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/10/16 11:42
# @Author  : CoderCharm
# @File    : session.py
# @Software: PyCharm
# @Github  : github/CoderCharm
# @Email   : wg_python@163.com
# @Desc    :
"""

"""

# from sqlalchemy import create_engine
# from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession

from common import logger
from core.config import settings

# engine = create_engine(settings.SQLALCHEMY_DATABASE_URL, pool_pre_ping=True, echo=True)  # echo=True 打印查询语句
# SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
logger.info(settings.ASYNCIO_SQLALCHEMY_DATABASE_URL)
# 创建数据库连接
async_engine = create_async_engine(
    settings.ASYNCIO_SQLALCHEMY_DATABASE_URL,
    echo=False,
    echo_pool=False,
    pool_pre_ping=True,
    pool_recycle=3600,
    pool_size=5,
    max_overflow=5,
    connect_args={}
)
# 创建数据库会话
session_factory = async_sessionmaker(
    autocommit=False,
    autoflush=False,
    bind=async_engine,
    expire_on_commit=True,
    class_=AsyncSession
)
